//
//  MYGlobal.m
//  PetExchange
//
//  Created by a on 2020/12/17.
//

#import "MYGlobal.h"
#import "GetLocation.h"
#import "LocationModel.h"
//水印存储路径
#define shuiyinPath [NSString stringWithFormat:@"%@/Documents/shuiyin.txt",NSHomeDirectory()]
@implementation MYGlobal
+(MYGlobal *)share{
    static MYGlobal *sharedGlobalInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedGlobalInstance = [[self alloc] init];
    });
    return sharedGlobalInstance;
}

-(id)init{
    self=[super init];
    if (self) {
        self.gwIP = @"";
        self.wechatFlag = 0;
        self.shuiyinDic = [NSMutableDictionary new];
        self.shuiyinDic = [self getDataWithPath:shuiyinPath];
        if(self.shuiyinDic.allKeys.count < 1){
            self.shuiyinDic[@"timeType"] = @"AB";
            //打卡开启状态
            NSMutableDictionary *dakaDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[DAKATYPE]){
                dakaDic[@"timeType"] = @"AB";
                dakaDic[@"1time"] = @"1";
                dakaDic[@"2address"] = @"1";
                dakaDic[@"3tianqi"] = @"1";
                dakaDic[@"4jingwei"] = @"1";
                dakaDic[@"5beizhu"] = @"0";
                self.shuiyinDic[DAKATYPE] = dakaDic;
            }
            
            //考勤开启状态
            NSMutableDictionary *kaoqinDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[KAOQINATYPE]){
                kaoqinDic[@"timeType"] =  @"AB";

                kaoqinDic[@"1time"] = @"2";
                kaoqinDic[@"2address"] = @"1";
                kaoqinDic[@"3tianqi"] = @"1";
                kaoqinDic[@"4jingwei"] = @"1";
                kaoqinDic[@"5beizhu"] = @"0";
                self.shuiyinDic[KAOQINATYPE] = kaoqinDic;
            }
            
            //工程记录开启状态
            NSMutableDictionary *gongchengDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[GONGCHENGTYPE]){
                gongchengDic[@"timeType"] =  @"AB";
                //gongchengDic[@"1time"] = @"2";
                gongchengDic[@"2name"] = @"1";
                gongchengDic[@"3quyu"] = @"1";
                gongchengDic[@"4sgnr"] = @"0";
                gongchengDic[@"5sgfzr"] = @"0";
                gongchengDic[@"6jlfzr"] = @"0";
                gongchengDic[@"7jsdw"] = @"0";
                gongchengDic[@"8jldw"] = @"0";
                gongchengDic[@"9sgdw"] = @"0";
                gongchengDic[@"10sjdw"] = @"0";
                gongchengDic[@"11ktdw"] = @"0";
                gongchengDic[@"12tianqi"] = @"1";
                gongchengDic[@"13jwd"] = @"1";
                gongchengDic[@"14beizhu"] = @"0";
                self.shuiyinDic[GONGCHENGTYPE] = gongchengDic;
            }
            
            //物业开启状态
            NSMutableDictionary *wuyeDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[WUYETYPE]){
                wuyeDic[@"timeType"] =  @"AB";
                wuyeDic[@"1time"] = @"1";
                wuyeDic[@"2address"] = @"1";
                wuyeDic[@"3tianqi"] = @"1";
                wuyeDic[@"4jingwei"] = @"1";
                wuyeDic[@"5beizhu"] = @"0";
                self.shuiyinDic[WUYETYPE] = wuyeDic;
            }
            
            //执勤巡逻开启状态
            NSMutableDictionary *zhiqinDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[ZHIQINTYPE]){
                zhiqinDic[@"timeType"] = @"AB";
 
                zhiqinDic[@"1zxry"] = @"1";
                zhiqinDic[@"2time"] = @"1";
                zhiqinDic[@"3address"] = @"1";
                zhiqinDic[@"4xlqy"] = @"0";
                zhiqinDic[@"5xljg"] = @"0";
                zhiqinDic[@"6tfsj"] = @"0";
                zhiqinDic[@"7tianqi"] = @"1";
                zhiqinDic[@"8jingwei"] = @"1";
                zhiqinDic[@"9beizhu"] = @"0";
                self.shuiyinDic[ZHIQINTYPE] = zhiqinDic;
            }
            
            //快递外卖开启状态
            NSMutableDictionary *kauaidDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[KUAIDITYPE]){
                kauaidDic[@"timeType"] = @"ABC";
      
                kauaidDic[@"1psr"] = @"1";
                kauaidDic[@"2psnr"] = @"1";
                kauaidDic[@"3psdd"] = @"1";
                kauaidDic[@"4sjr"] = @"0";
                kauaidDic[@"5sjrdh"] = @"0";
                kauaidDic[@"6jjr"] = @"0";
                kauaidDic[@"7jjrdh"] = @"0";
                kauaidDic[@"8kdgs"] = @"0";
                kauaidDic[@"9time"] = @"1";
                kauaidDic[@"10tianqi"] = @"1";
                kauaidDic[@"11jingwei"] = @"0";
                kauaidDic[@"12beizhu"] = @"0";
                self.shuiyinDic[KUAIDITYPE] = kauaidDic;
            }
            
            //日常巡检开启状态
            NSMutableDictionary *richangDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[RICHANGTYPE]){

                richangDic[@"timeType"] = @"AB";
                richangDic[@"1time"] = @"1";
                richangDic[@"2xjdd"] = @"1";
                richangDic[@"3xjry"] = @"1";
                richangDic[@"4xjnr"] = @"0";
                richangDic[@"5tianqi"] = @"1";
                richangDic[@"6jingwei"] = @"1";
                richangDic[@"7beizhu"] = @"0";
                self.shuiyinDic[RICHANGTYPE] = richangDic;
            }
            
            //家政服务开启状态
            NSMutableDictionary *jiazhengDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[JIAZHENGTYPE]){
 
                jiazhengDic[@"timeType"] = @"ABC";
                jiazhengDic[@"1time"] = @"1";
                jiazhengDic[@"2fwdd"] = @"1";
                jiazhengDic[@"3jzry"] = @"1";
                jiazhengDic[@"4gznr"] = @"1";
                jiazhengDic[@"5tianqi"] = @"1";
                jiazhengDic[@"6jingwei"] = @"0";
                jiazhengDic[@"7beizhu"] = @"0";
                self.shuiyinDic[JIAZHENGTYPE] = jiazhengDic;
            }
            
            //会议纪要开启状态
            NSMutableDictionary *hyjyDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[HUIYITYPE]){

                hyjyDic[@"timeType"] = @"AB";
                hyjyDic[@"1time"] = @"1";
                hyjyDic[@"2hymc"] = @"1";
                hyjyDic[@"3hyrs"] = @"1";
                hyjyDic[@"4hynr"] = @"0";
                hyjyDic[@"5hydd"] = @"1";
                hyjyDic[@"6zcr"] = @"0";
                hyjyDic[@"7yhry"] = @"0";
                hyjyDic[@"8tianqi"] = @"1";
                hyjyDic[@"9jingwei"] = @"0";
                hyjyDic[@"10beizhu"] = @"0";
                self.shuiyinDic[HUIYITYPE] = hyjyDic;
            }
            
            //房屋验收开启状态
            NSMutableDictionary *fwysDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[FANGWUTYPE]){

                fwysDic[@"timeType"] = @"ABC";
                fwysDic[@"1dkr"] = @"1";
                fwysDic[@"2khmc"] = @"1";
                fwysDic[@"3time"] = @"1";
                fwysDic[@"4dd"] = @"1";
                fwysDic[@"5tianqi"] = @"1";
                fwysDic[@"6jwd"] = @"0";
                fwysDic[@"7beizhu"] = @"0";
                self.shuiyinDic[FANGWUTYPE] = fwysDic;
            }
            
            //任务工单开启状态
            NSMutableDictionary *rwgdDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[RENWUTYPE]){

                rwgdDic[@"timeType"] = @"ABC";
                rwgdDic[@"1jdr"] = @"1";
                rwgdDic[@"2gcxm"] = @"1";
                rwgdDic[@"3khmc"] = @"1";
                rwgdDic[@"4lxfs"] = @"1";
                rwgdDic[@"5dd"] = @"1";
                rwgdDic[@"6time"] = @"1";
                rwgdDic[@"7tianqi"] = @"1";
                rwgdDic[@"8jwd"] = @"0";
                rwgdDic[@"9beizhu"] = @"0";
                self.shuiyinDic[RENWUTYPE] = rwgdDic;
            }
            
            //外派学习开启状态
            NSMutableDictionary *wpxxDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[WAIPAITYPE]){

                wpxxDic[@"timeType"] = @"AB";
                wpxxDic[@"1wpry"] = @"0";
                wpxxDic[@"2wpdd"] = @"0";
                wpxxDic[@"3wpnr"] = @"0";
                wpxxDic[@"4time"] = @"1";
                wpxxDic[@"5dd"] = @"1";
                wpxxDic[@"6tianqi"] = @"1";
                wpxxDic[@"7jwd"] = @"1";
                wpxxDic[@"8beizhu"] = @"0";
                self.shuiyinDic[WAIPAITYPE] = wpxxDic;
            }
            
            //关爱老人开启状态
            NSMutableDictionary *galrDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[GUANAITYPE]){

                galrDic[@"timeType"] = @"ABC";
                galrDic[@"1gzxm"] = @"1";
                galrDic[@"2hgxm"] = @"1";
                galrDic[@"3lxfs"] = @"0";
                galrDic[@"4time"] = @"1";
                galrDic[@"5dd"] = @"1";
                galrDic[@"6tianqi"] = @"1";
                galrDic[@"7jwd"] = @"0";
                galrDic[@"8beizhu"] = @"0";
                self.shuiyinDic[GUANAITYPE] = galrDic;
            }
            
            //旅游打卡开启状态
            NSMutableDictionary *lydkDic = [NSMutableDictionary new];
            if(!self.shuiyinDic[LVYOUTYPE]){
                lydkDic[@"timeType"] = @"ABC";
                lydkDic[@"1tianqi"] = @"1";
                lydkDic[@"2jdmc"] = @"1";
                lydkDic[@"3ylry"] = @"0";
                lydkDic[@"4ylrs"] = @"0";
                lydkDic[@"5time"] = @"1";
                lydkDic[@"6add"] = @"1";
                lydkDic[@"7jwd"] = @"1";
                lydkDic[@"8beizhu"] = @"0";
                self.shuiyinDic[LVYOUTYPE] = lydkDic;
            }
            [self saveDataWithDict:self.shuiyinDic withPath:shuiyinPath];
        }else{
//            self.shuiyinDic[DAKATYPE][@"5beizhu"] = @"0";
//            self.shuiyinDic[KAOQINATYPE][@"5beizhu"] = @"0";
//            self.shuiyinDic[GONGCHENGTYPE][@"14beizhu"] = @"0";
//            self.shuiyinDic[WUYETYPE][@"5beizhu"] = @"0";
//            self.shuiyinDic[ZHIQINTYPE][@"9beizhu"] = @"0";
//            self.shuiyinDic[KUAIDITYPE][@"12beizhu"] = @"0";
//            self.shuiyinDic[RICHANGTYPE][@"7beizhu"] = @"0";
//            self.shuiyinDic[HUIYITYPE][@"10beizhu"] = @"0";
        }
    }
    return self;
}
-(NSString *)getdayAndWeek:(NSString *)type{
    if(type){
        NSString *day = [Helper getCurrentTimes:@"yyyy.MM.dd"];
        NSString *week = [self getWeekDay:[NSDate new].weekday];
        NSString *time = [Helper getCurrentTimes:@"HH:mm"];
        NSString *times = [Helper getCurrentTimes:@"HH:mm:ss"];
        if([type isEqualToString:@"ABC"]){
            return [NSString stringWithFormat:@"%@ %@ %@",day,week,time];
        }else if([type isEqualToString:@"ACs"]){
            return [NSString stringWithFormat:@"%@ %@",day,times];
        }else if([type isEqualToString:@"AC"]){
            return [NSString stringWithFormat:@"%@ %@",day,time];
        }else if([type isEqualToString:@"AB"]){
            return [NSString stringWithFormat:@"%@ %@",day,week];
        }else if([type isEqualToString:@"BC"]){
            return [NSString stringWithFormat:@"%@ %@",week,time];
        }else if([type isEqualToString:@"A"]){
            return [NSString stringWithFormat:@"%@",day];
        }else if([type isEqualToString:@"B"]){
            return [NSString stringWithFormat:@"%@",week];
        }else if([type isEqualToString:@"C"]){
            return [NSString stringWithFormat:@"%@",time];
        }
    }else{
        return [NSString stringWithFormat:@"%@ %@",[Helper getCurrentTimes:@"yyyy.MM.dd"],[self getWeekDay:[NSDate new].weekday]];
    }
    return  nil;
}

-(NSString *)getWeekDay:(NSInteger)index{
    if(index == 0){
        return  LocalizedString(@"星期日");
    }else if(index == 1){
        return LocalizedString(@"星期一");
    }else if(index == 2){
        return LocalizedString(@"星期二");
    }else if(index == 3){
        return LocalizedString(@"星期三");
    }else if(index == 4){
        return LocalizedString(@"星期四");
    }else if(index == 5){
        return LocalizedString(@"星期五");
    }else if(index == 6){
        return LocalizedString(@"星期六");
    }
    return LocalizedString(@"未知");
}

- (void)saveData{
    [self saveDataWithDict:self.shuiyinDic withPath:shuiyinPath];
}
//保存数据
-(void)saveDataWithDict:(NSDictionary *)dict  withPath:(NSString *)path{
    //DLog(@"dict===%@",dict);
    if (dict == nil) {
        return;
    }
    NSData *resultData= [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSFileManager *fm=[NSFileManager defaultManager];
    if (![fm fileExistsAtPath:path]) {
        [fm createFileAtPath:path contents:nil attributes:nil];
    }
    [resultData writeToFile:path atomically:YES];
}
//得到数据
-(NSMutableDictionary *)getDataWithPath:(NSString *)path{
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSMutableDictionary *dict;
    if (data) {
        dict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:nil];
    }else{
        dict = [[NSMutableDictionary alloc] init];
    }
    return dict;
}

@end
